package com.fastCms.manager.bim.controller;


import com.fastCms.business.bim.manage.AreaManageService;
import com.fastCms.business.bim.pojo.po.AreaDeviceRelPO;
import com.fastCms.business.bim.pojo.po.AreaSavePO;
import com.fastCms.business.bim.pojo.vo.AreaVO;
import com.fastCms.business.bim.pojo.vo.DeviceInfoVO;
import com.fastCms.business.frame.response.ApiResponse;
import com.fastCms.manager.frame.annotation.UserAccess;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 区域管理 前端控制器
 * </p>
 *
 * @author liusq
 * @since 2021-04-05
 */
@RestController
@RequestMapping("/area")
@Api(value = "AreaController", tags = "后端-区域相关接口")
@UserAccess
public class AreaController {

    @Autowired
    private AreaManageService areaManageServiceImpl;

    @ApiOperation(value = "", notes = "")
    @GetMapping("/areaList")
    public ApiResponse<List<AreaVO>> areaList() {
        ApiResponse<List<AreaVO>> detail = areaManageServiceImpl.areaList();
        return detail;
    }

    @ApiOperation(value = "新增或修改区域", notes = "")
    @PostMapping("/saveOrUpdateArea")
    public ApiResponse<Boolean> saveOrUpdateArea(@RequestBody AreaSavePO savePO) {
        ApiResponse<Boolean> detail = areaManageServiceImpl.saveOrUpdateArea(savePO);
        return detail;
    }

    @ApiOperation(value = "获取区域全名称", notes = "")
    @GetMapping("/getFullAreaName/{areaId}")
    public ApiResponse<String> getFullAreaName(@PathVariable Integer areaId) {
        ApiResponse<String> result = areaManageServiceImpl.getFullAreaName(areaId);
        return result;
    }

    @ApiOperation(value = "获取区域详情", notes = "")
    @GetMapping("/getDetail/{areaId}")
    public ApiResponse<AreaVO> getDetail(@PathVariable Integer areaId) {
        ApiResponse<AreaVO> detail = areaManageServiceImpl.getDetail(areaId);
        return detail;
    }

    @ApiOperation(value = "删除区域", notes = "")
    @GetMapping("/delete/{areaId}")
    public ApiResponse<Boolean> delete(@PathVariable Integer areaId) {
        ApiResponse<Boolean> result = areaManageServiceImpl.delete(areaId);
        return result;
    }

    @ApiOperation(value = "区域下关联设备", notes = "")
    @PostMapping("/relDevice")
    public ApiResponse<Boolean> relDevice(@RequestBody AreaDeviceRelPO areaDeviceRelPO) {
        ApiResponse<Boolean> detail = areaManageServiceImpl.relDevice(areaDeviceRelPO);
        return detail;
    }

    @ApiOperation(value = "获取某区域下的所有设备", notes = "")
    @GetMapping("/getDevicesByAreaId/{areaId}")
    public ApiResponse<List<DeviceInfoVO>> getDevicesByAreaId(@PathVariable Integer areaId) {
        ApiResponse<List<DeviceInfoVO>> detail = areaManageServiceImpl.getDevicesByAreaId(areaId);
        return detail;
    }

    @ApiOperation(value = "删除某区域下的某设备", notes = "")
    @GetMapping("/deleteDeviceRel/{areaId}/{deviceId}")
    public ApiResponse<Boolean> deleteDeviceRel(@PathVariable Integer areaId, @PathVariable Integer deviceId) {
        ApiResponse<Boolean> detail = areaManageServiceImpl.deleteDeviceRel(areaId, deviceId);
        return detail;
    }

}

